package com.github.thinwonton.springboot.showcase.webservice.controller;

import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 计数控制器
 *
 * @author hugo
 * @date 2018/8/16
 */
@RestController
public class CountController {

    @RequestMapping("/count")
    @ResponseBody
    public int getCount(@RequestParam(name = "source") int source) throws Exception {
        // 创建动态客户端
        JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
        Client client = dcf.createClient("http://localhost:8002/services/CountService?wsdl");
        Object[] results = client.invoke("getCount", source);
        return (int) results[0];
    }
}
